import * as CONSTANT from "../constant.js";
import {getData} from "@/utils/localstorage.js";

const defaultState = getData("currentUser")
const userReducer = (state = defaultState, action) => {

    switch (action.type) {
        case CONSTANT.USER_SYNC:
            let currentUser = action.payload;
            if (currentUser) {
                state = currentUser;
            } else {
                state = defaultState;
            }
            return state;
        case CONSTANT.USER_DELETE:
            state = null;
            return state;
        default:
            return state;
    }
}
export default userReducer;